<?php
include ("common/connectDB.php");

class Model {
	
	// Get all game
	public function getListGame() {
		$queryGetAllGames = "SELECT * FROM tbl_game";
		$allGames = mysql_query($queryGetAllGames);
		return $allGames;
	}
	
	// Get game by game_id
	public function getGame($game_id) {
		$allGames = $this->getListGame();
		while($row = mysql_fetch_array($allGames)) {
			if($row['game_id'] == $game_id) {
				$game = array(
					"game_id" => $row['game_id'],
					"game_name" => $row['game_name'],
					"game_description" => $row['game_description'],
					"game_detail" => $row['game_detail']
				);
			}
		}
		return $game;
	}
	
	// Get list game online
	public function getListGameOnline() {
		$queryGetListGameOnline = "
			SELECT *
			FROM gameonline
			ORDER BY game_id DESC
		";
		$listGameOnline = mysql_query($queryGetListGameOnline);
		return $listGameOnline;
	}
	
	// Get num of game online
	public function getNumOfGameOnline() {
		$result = mysql_query("SELECT COUNT(*) AS count FROM gameonline");
		$countGame = mysql_fetch_array($result);
		return $countGame['count'];
	}
	
	// Get list game offline
	public function getListGameOffline() {
		$queryGetListGameOffline = "
			SELECT *
			FROM gameoffline
			ORDER BY game_id DESC
		";
		$listGameOffline = mysql_query($queryGetListGameOffline);
		return $listGameOffline;
	}
	
	// Get num of game offline
	public function getNumOfGameOffline() {
		$result = mysql_query("SELECT COUNT(*) AS count FROM gameoffline");
		$countGame = mysql_fetch_array($result);
		return $countGame['count'];
	}
	
}